using ELF.Modules;
using ELF.Modules.Ocelot;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using Ocelot.ServiceDiscovery;

namespace IdentityApi;

public class ElfOcelotModule : IModule
{

    public async Task ConfigureServicesAsync(IHostApplicationBuilder builder)
    {
        builder.Configuration
            .SetBasePath(builder.Environment.ContentRootPath)
            .AddOcelot();
        //ServiceDiscoveryFinderDelegate serviceDiscoveryFinder = (provider, config, route)
        //    => new MyServiceDiscoveryProvider(provider, config, route);
        //var ocelotBuilder = builder.Services
        //    .AddSingleton(serviceDiscoveryFinder).AddOcelot(builder.Configuration);
        builder.Services.AddOcelot().AddConsul();
       await Task.CompletedTask;
    }

    public async Task InitializeAsync(IApplicationBuilder app)
    {
        await app.UseOcelot();
        await Task.CompletedTask;
    }
}
